package com.kangye.learnstudent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kangye.learnstudent.entity.StudentPaper;
import com.kangye.learnstudent.entity.User;
import com.kangye.learnstudent.mapper.StudentPaperMapper;
import com.kangye.learnstudent.service.StudentPaperService;
import com.kangye.learnstudent.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: learndeduo
 * @description: 实现学生试卷逻辑接口
 * @author: 索腾龙
 * @create: 2021-05-17 11:06
 **/
@Service
@Transactional
public class StudentPaperServiceImpl implements StudentPaperService {
    @Autowired
    private StudentPaperMapper studentPaperMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    //根据年级和科目查询各科和各年级的试卷
    @Override
    public ViewJsonObject selStudentTest(Integer spGradeId, Integer spSubjectId, Integer page, Integer limit) {
        //把当前页和每页显示的条数传进来
        PageHelper.startPage(page, limit);
        //根据年及和科目查询各科和各年级的全部试卷
        List<StudentPaper> list = studentPaperMapper.selStudentTest(spGradeId, spSubjectId);
        //创建分页对象,把数据存在pageInfo里
        PageInfo<StudentPaper> pageInfo = new PageInfo<StudentPaper>(list);
        //返回json也么
        return new ViewJsonObject(pageInfo.getList(), pageInfo.getTotal());



    }
    //根据学生id和卷子的id修改做题试卷的状态(做了卷子了没有)和提交卷子的时间
    @Override
    public Integer seleStudentTestPaperpage(Timestamp spSubmitTime,Integer spUserId, Integer spId) {
        //返回接收mapper文件里的sql语句
        return studentPaperMapper.seleStudentTestPaperpage(spSubmitTime,spUserId,spId);

    }

    //查询部分试卷信息
    @Override
    public ViewJsonObject getStudentPaper(User user,Integer page, Integer limit) {
        //把当前页和每页显示的条数传进来
        PageHelper.startPage(page, limit);
        List<StudentPaper> list = studentPaperMapper.getStudentPaper(user);
            //创建分页对象,把数据存在pageInfo里
            PageInfo<StudentPaper> pageInfo = new PageInfo<StudentPaper>(list);
            //返回json也么
            return new ViewJsonObject(pageInfo.getList(), pageInfo.getTotal());
    }
}